﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Sport
{
	public partial class Form1 : Form
	{
		SoccerTable Table = new SoccerTable();

		public Form1()
		{
			InitializeComponent();
			var taban = Table.CreateTeam(0, "Tabán FC");
			var blitzkrieg = Table.CreateTeam(1, "Blitzkrieg Bop");
			var kifu = Table.CreateTeam(2, "KIFU");
			var nafc = Table.CreateTeam(3, "N.A.F.C");
			var royal = Table.CreateTeam(4, "Royal Flesh");
			var pasaref = Table.CreateTeam(5, "FC Pasaref");
			var dagadt = Table.CreateTeam(6, "Dagadt Ribancok");
			var dream = Table.CreateTeam(7, "Dream Team Futsal");
			var magic = Table.CreateTeam(8, "Magic Monkeys");
			var gse = Table.CreateTeam(9, "GSE");
			var cabonero = Table.CreateTeam(10, "FC Cabonero");
			var majmedence = Table.CreateTeam(11, "Májmedence FC");

			//round1
			Table.AddResult(1,taban, blitzkrieg, 3, 2);
			Table.AddResult(1, kifu, nafc, 7, 4);
			Table.AddResult(1, royal, pasaref, 2, 2);
			Table.AddResult(1, dagadt, dream, 5, 5);
			Table.AddResult(1, magic, gse, 2, 4);
			Table.AddResult(1, cabonero, majmedence, 8, 4);
			//round2
			Table.AddResult(2,taban, royal, 5, 1);
			Table.AddResult(2, blitzkrieg, pasaref, 4, 1);
			Table.AddResult(2, kifu, dream, 1, 2);
			Table.AddResult(2, nafc, majmedence, 1, 3);
			Table.AddResult(2, magic, cabonero, 6, 5);
			Table.AddResult(2, dagadt, gse, 2, 1);
			//round3
			Table.AddResult(3,taban, gse, 0, 4);
			Table.AddResult(3, blitzkrieg, royal, 4, 3);
			Table.AddResult(3, dagadt, cabonero, 1, 4);
			Table.AddResult(3, pasaref, majmedence, 6, 8);
			Table.AddResult(3, kifu, magic, 2, 3);
			Table.AddResult(3, nafc, dream, 6, 8);
			//round4
			Table.AddResult(4,taban, cabonero, 3, 5);
			Table.AddResult(4, blitzkrieg, gse, 1, 9);
			Table.AddResult(4, kifu, majmedence, 10, 1);
			Table.AddResult(4, pasaref, dream, 6, 11);
			Table.AddResult(4, nafc, magic, 2, 4);
			Table.AddResult(4, royal, dagadt, 2, 4);
			//round5
			Table.AddResult(5, taban, nafc, 3, 5);
			Table.AddResult(5, blitzkrieg, dagadt, 1, 3);
			Table.AddResult(5, royal, magic, 3, 5);
			Table.AddResult(5, pasaref, cabonero, 2, 11);
			Table.AddResult(5, dream, majmedence, 3, 4);
			Table.AddResult(5, kifu, gse, 2, 1);
			//round6
			Table.AddResult(6, taban, magic, 2, 1);
			Table.AddResult(6, blitzkrieg, dream, 3, 2);
			Table.AddResult(6, pasaref, gse, 2, 6);
			Table.AddResult(6, royal, majmedence, 4, 4);
			Table.AddResult(6, kifu, dagadt, 1, 4);
			Table.AddResult(6, nafc, cabonero, 0, 8);
			//round7
			Table.AddResult(7, taban, majmedence, 2, 8);
			Table.AddResult(7, blitzkrieg, kifu, 0, 4);
			Table.AddResult(7, gse, cabonero, 1, 1);
			Table.AddResult(7, pasaref, dagadt, 2, 3);
			Table.AddResult(7, nafc, royal, 6, 1);
			Table.AddResult(7, dream, magic, 4, 7);
			
			Table.BuildTable();

			foreach (var t in Table.table)
			{
				Console.WriteLine(t);
			}
			String table = "<table><tr><td><table>";
			foreach (SoccerEntry e in Table.table)
			{
				table += "<tr>";
				table += "<td>" + e.team.name + "</td>";
				table += "<td>" + e.win + "</td>";
				table += "<td>" + e.draw + "</td>";
				table += "<td>" + e.lost + "</td>";
				table += "<td>" + e.GoalFor + ":" + e.GoalAgainst + "</td>";
				table += "<td>" + e.GoalDiff + "</td>";
				table += "<td>" + e.points + "</td>";
				table += "</tr>";
			}
			
			Dictionary<SportTeam, int[]> rec = new Dictionary<SportTeam, int[]>();
			foreach (SportTeam t in Table.teams)
				rec.Add(t, new int[7]);
			for (int i = 1; i < 8; i++)
			{
				Table.BuildTable(i);
				foreach (TableEntry e in Table.table)
					rec[e.team][i - 1] = e.points;
			}

			Bitmap bmp = new Bitmap(500, 500);
			Graphics G = Graphics.FromImage(bmp);
			G.Clear(Color.White);
			foreach (var r in rec)
			{
				Point[] pts = new Point[r.Value.Length];
				for (int i = 0; i < r.Value.Length; i++)
					pts[i] = new Point(i * 50, 500 - 20 * r.Value[i]);
				G.DrawLines(r.Key == majmedence ? Pens.Red : Pens.Black, pts);
			}
			G.Dispose();
			bmp.Save("points.png");
			bmp.Dispose();

			table += "</table></td><td><img src=\"file:///C:/C%23/Sport/bin/debug/points.png\"></td></tr></table>";
			webBrowser1.DocumentText = "<html><head><body bgcolor=#CCFF88>" + table + "</body></html>";
		}

		public void Draw()
		{
		}
	}
}
